var apiUrl=contextPath+"/estate/projectProcdef/list";
var listVue=new Vue({
  el: '#projectProcdefIndex',
  data: {
	  params:{
		  pageSize:10,
		  pageNum:1,
		  projectId:'',
		  procdefId:'',
		  procName:'',
		  procType:''
	  },
  	  ppList:[],
  	  projectList:[],
  	  processTypeList:[],
  	  permission:{
  		  query:false,
  		  edit:false,
  		  setUp:false
  	  }
  },
  mounted:function(){
	  //初始化项目
	  this.initProject();
	  //初始化流程类型
	  this.initProcessType();
	  //初始化权限
	  this.initPermission();
  },
  methods: {
	 queryList:function(){
		 this.params.pageNum=1;
		 this.getList();
	 },
     getList:function() {
    	var _self = this;
    	if(_self.params.projectId==""){
    		layer.tips('项目必选', '#queryProjectId', {
    			  tips: [2, '#FF5722'],
    			  time: 2000
    		});
    		return;
    	}
    	var loadIndex = layer.load(0, {shade: false});
     	$.ajax({
    		type:'post',
            url: apiUrl,
    	    data:_self.params,
    	    dataType:'json',
    	    success: function(res){
    	    	layer.close(loadIndex);
    	    	if(res.res=="1"){
    	    		var rows=res.obj.rows;
        	    	_self.ppList=rows;
        	    	//初始化分页
                	var pages=res.obj.totalPages;
    	        	var current=res.obj.pageNumber;
            	    laypage({
            		  cont: $('#pagination'), //容器。值支持id名、原生dom对象，jquery对象,
            		  pages: pages, //总页数
            		  curr:current,
            		  skip: true, //是否开启跳页
            		  skin: 'molv',
            		  groups: 3, //连续显示分页数
            		  jump: function(obj,first){
            			  if(!first){
            				  _self.params.pageNum=obj.curr;
            				  _self.getList();
            			  }
            		  }
            		});
            	    
    	    	}else{
    	    		layer.close(loadIndex);
    	    		layer.alert(res.resMsg);
    	    	}
    	    	
    	    },
    	    error:function(res){
    	    	
    	    }
    	});   
     },
     updateProjectProcdef:function(id,procdefId){
        layer.open({
 			type:2,
 		    title: "修改",
 		    closeBtn: 2,
 		    shadeClose: true,
 		    area: ['550px', '180px'],
 		    fix: false, //不固定
 		    content: contextPath +'/estate/projectProcdef/setProjectProcdef?id='+id+"&procdefId="+procdefId
 		});
     },
     currentType:function(pdId){
    	 var width=document.documentElement.clientWidth * 0.85+"px";
    	 var height=document.documentElement.clientHeight * 0.85+"px";
    	 layer.open({
    		    type: 2,
    		    title: "流程【图片】",
    		    shadeClose: true,
    		    maxmin: true,
    		    area: [width, height],
    		    content: contextPath+"/backstage/workflow/process/resource/read?resourceType=image"+"&processDefinitionId="+pdId
    	});
     },
     setNodeUser:function (processDefinitionId,projectId){
    		var jumpUrl=contextPath+"/backstage/workflow/process/toNodeList?processDefinitionId="+processDefinitionId+"&projectId="+projectId;
    		window.location.href=jumpUrl;
     },
     initProject:function(){
    	    var _self = this;
    	    var url=contextPath+"/customer/follow/returnProjectName";
    		$.ajax({
    			type: 'post',
    	        url: url,
    		    data: {
    		    	resourcesCode:'menu_0003_0001',
    		    	resourcesName:'resName_pro_list'
    		    },
    		    dataType:'json',
    		    success: function(res){
    		    	var list=res;
    		    	_self.projectList=list;
    		    	_self.defaultProject();
    		    }
    		});
     },
     defaultProject:function(){
    	 if(projectId=="")return;
    	 var pList=this.projectList;
    	 for(var i = 0;i<pList.length;i++){
    		 var project=pList[i];
    		 if(project.id==projectId){
    			 this.params.projectId=projectId; 
    			 this.getList();
    			 break;
    		 }
    	 }
     },
     initProcessType:function(){
    	var _self = this;
    	//系统定义流程
 	    var url=contextPath+"/processComponent/processTypeList";
 		$.ajax({
 			type: 'post',
 	        url: url,
 		    data: {
 		    },
 		    dataType:'json',
 		    success: function(res){
 		    	var list=res.obj;
 		    	_self.processTypeList=list;
 		    }
 		});
     },
     initPermission(){
    	var _self = this;
    	var objList=JSON.parse(permitBtn);
 		var query="estate:projectProcdef:list";
 		var edit="estate:projectProcdef:edit";
 		var setUp="estate:projectProcdef:setUp";
 		for(ob in objList){
 			var permission=objList[ob];
 			if(permission==query){
 				_self.permission.query=true;
 			}else if(permission==edit){
 				_self.permission.edit=true;
 			}else if(permission==setUp){
 				_self.permission.setUp=true;
 			}
 		}
     },
     clearForm:function(){
    	 this.params.projectId='';
    	 this.params.procdefId='';
    	 this.params.procName='';
    	 this.ppList=[];
     }
  }
})

